package com.lovo.MapWork;

import java.lang.annotation.ElementType;
import java.security.spec.ECField;
import java.util.*;

public class MapWork_2 {
    public static void main(String[] args) {
        int a = 0, b = 0, c = 0;
        String[] str = {"a", "b", "a", "b", "c", "a", "b", "c", "b"};
        for (int i = 0; i < str.length; i++) {
            if (str[i].equals("a")) {
                a++;
            } else if (str[i].equals("b")) {
                b++;
            } else {
                c++;
            }
        }
        List<String> list = Arrays.asList(str);
        for (Object obj : list) {
            System.out.println(obj);
        }
        System.out.println("\n");

        //把list转换为set  去重
        HashSet hashSet = new HashSet();
        hashSet.addAll(list);

        //set转换为list
        ArrayList list1 = new ArrayList();
        list1.addAll(hashSet);

        Map map = new HashMap();
        map.put(list1.get(0), a);
        map.put(list1.get(1), b);
        map.put(list1.get(2), c);

        Set key = map.keySet();
        for (Object item : key) {
            System.out.println(item + " " + map.get(item));
        }
    }
}
